package com.shhm.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.shhm.business.mapper.AnnouncementMapper;
import com.shhm.business.service.AnnouncementService;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.common.AnnouncementEntity;
import com.shhm.common.utils.MybatisPlusUtil;
import com.shhm.common.utils.ResponseUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/12 下午8:39
 */
@Service
public class AnnouncementServiceImpl implements AnnouncementService {
    @Resource
    private AnnouncementMapper announcementMapper;

    @Override
    public AjaxResultPlus pageSearchList(Integer pageNum, Integer pageSize, AnnouncementEntity entity) {
        PageDTO<AnnouncementEntity> userPage = new PageDTO<>(pageNum, pageSize);
        QueryWrapper<AnnouncementEntity> qw = MybatisPlusUtil.buildSearchQueryWrapper(entity);
        PageDTO<AnnouncementEntity> list = announcementMapper.selectPage(userPage, qw);
        return AjaxResultPlus.success(list,false);
    }

    @Override
    public AjaxResultPlus add(AnnouncementEntity entity) {
        entity.createLocalDateTime();
        return ResponseUtil.sqlExeIsSuccess(announcementMapper.insert(entity));
    }

    @Override
    public AjaxResultPlus update(AnnouncementEntity entity) {
        return ResponseUtil.sqlExeIsSuccess(announcementMapper.updateById(entity));
    }

    @Override
    public AjaxResultPlus delete(RequestList ids) {
        List<Object> list = ids.getList();
        return ResponseUtil.sqlExeIsSuccess(announcementMapper.deleteByIds(list));
    }

    @Override
    public AjaxResultPlus productTypeList(Integer pageNum, Integer pageSize, Integer isPage) {
        if (isPage==0) {
            List<AnnouncementEntity> list = announcementMapper.selectList(null);
            return AjaxResultPlus.success(list,false);
        }
        PageDTO<AnnouncementEntity> userPage = new PageDTO<>(pageNum, pageSize);
        PageDTO<AnnouncementEntity> list=announcementMapper.selectPage(userPage, null);
        return AjaxResultPlus.custom(200, false)
                .put("data",list)
                .put("operateStr","*");
    }
}
